<style>
    .flash{
        background: none repeat scroll 0 0 transparent !important;
        height: 25px !important;
        left: 128px !important;
        opacity: 0 !important;
        overflow: hidden !important;
        position: absolute !important;
        top: 1px !important;
        width: 88px !important;
        z-index: 99 !important;
    }
    #uploadQueue{
        margin: 7px 0;
    }
    .message{
        display: none;
    }
    input {
        width: 210px;
    }
</style>

<div class="container">

    <div class="page-header">
        <div class="row">
            <h1 class="span8">Add Folders / Files</h1>
            <span class="span4">

            </span>
        </div>


    </div>

    <div class="row">

        <div class="span8">


            <div id="wpbody-content">

                <div style="display: none;" class="wrap" id="slider">

                    <ul id="tabs">

                        <li><a href="#uploadimage">Upload Files</a></li>
                        <!--<li><a href="#uploadvideo">Upload Videos</a></li>-->
                        <li><a href="#addgallery">Add new folder</a></li>

                    </ul>

                    <!--UPLOAD IMAGES-->
                    <div id="uploadimage">

                        <h2> Upload Files </h2>

                        <form accept-charset="utf-8" action="<?= base_url() ?>documents/submit_gallery" enctype="multipart/form-data" method="POST" id="uploadimage_form" name="uploadimage">           

                            <input type="hidden" value="new-pictures" name="post_action">

                            <table class="form-table">

                                <tbody>

                                    <tr valign="top">

                                        <td class="upload_text">Upload file</td>

                                        <td>

                                            <div id="plupload-upload-ui">

                                                <div>
                                                    Choose files to upload                        
                                                    <input type="button" class="button btn btn-mini" value="Select Files" id="plupload-browse-button" style="position: relative; z-index: 0;">
                                                </div>

                                                <div id="uploadQueue"></div>

                                            </div>

                                        </td>

                                    </tr> 

                                    <tr valign="top"> 

                                        <td class="upload_text">in to</td> 

                                        <td>

                                            <?
                                            $_GET['_cur_level'] = ''; 

                                            function parents_finder ($parent_ID = 0, $page_type, $clean=FALSE){

                                            $CI = & get_instance ();

                                            $galleries = $CI->document_model->view_all_children($parent_ID, $page_type);

                                            foreach ($galleries as $oneGallery):

                                            $cur_ID = $oneGallery['ID'];

                                            if($clean){

                                            ?><option value="<?= $cur_ID ?>"><?= repeat_sign('&nbsp;', $_GET['_cur_level'] * 3) . '- ' . $oneGallery['title'] ?></option><?
                                }else{
                                ?><option value="<?= $cur_ID ?><--delimiter!--><?= $oneGallery['path'] ?>"><?= repeat_sign('&nbsp;', $_GET['_cur_level'] * 3) . '- ' . $oneGallery['title'] ?></option><?
                                }

                                if(count($CI->document_model->view_all_children($cur_ID, $page_type))>0):

                                $_GET['_cur_level']++;
                                parents_finder($cur_ID, $page_type, $clean);

                                endif;

                                endforeach;

                                $_GET['_cur_level'] --;

                                }

                                ?>

                                <select id="galleryselect" name="galleryselect">
                                    <option value="0">Choose folder</option>
                                    <?foreach (config_item('page_types') as $page_type):?>
                                    <optgroup label="<?= ucfirst($page_type); ?>">
                                        <?= parents_finder(0, $page_type); ?>
                                        <? endforeach; ?>
                                </select>

                                <?
                                unset($_GET['_cur_level']);
                                ?>




                                <br>                
                                <br>

                                </td> 

                                </tr> 

                                </tbody>

                            </table>

                            <div class="submit row"> 

                                <span class="span2 ml-15> save2" style="width: 130px !important;"><input type="button" value="Upload files" class="btn" id="plupload_btn" name="uploadimage"></span>
                                <div class="span5 loader">
                                    <div style="float:left; width: 34px"><img id="ajax-loading" class="ajax-loading" src="<?= base_url() ?>assets/img/backgnds/loading.gif" style="visibility: hidden;"></div>
                                    <div style="float:left" class="message"><p>Please wait while files are being uploaded</p></div>

                                </div>

                            </div>

                        </form>

                    </div>
                    <!--/UPLOAD IMAGES-->

                    <!--UPLOAD VIDEO-->
                    <div id="uploadvideo" class="clearfix" style="display: none;">

                        <div class="v-left">

                            <h2> Upload Videos </h2>

                            <form accept-charset="utf-8" action="<?= base_url() ?>documents/submit_gallery" enctype="multipart/form-data" method="POST" id="uploadvideo_form" name="uploadvideo">           

                                <input type="hidden" value="new-videos" name="post_action">

                                <table class="form-table">

                                    <tbody>

                                        <tr valign="top">

                                            <td class="upload_text">Upload video</td>

                                            <td>

                                                <div>

                                                    <div>
                                                        <input type="text" name="yt-link" id="yt-link" value="" />                       
                                                        <input type="button" class="button btn btn-mini" value="Check Link" id="yt-check" style="position: relative; z-index: 0;">
                                                    </div>

                                                </div>

                                            </td>

                                        </tr> 

                                        <tr valign="top">

                                            <td class="upload_text">Name</td>

                                            <td>

                                                <div>

                                                    <div>
                                                        <input type="text" name="yt-name" id="yt-name" value="" />                       
                                                    </div>

                                                </div>

                                            </td>

                                        </tr> 

                                        <tr valign="top"> 

                                            <td class="upload_text">in to</td> 

                                            <td>

                                                <select id="galleryselect2" name="galleryselect2">
                                                    <option value="0">Choose gallery</option>

                                                    <? foreach ($all_documents as $one_document): ?>
                                                    <option value="<?= $one_document['ID'] ?><--delimiter!--><?= $one_document['path'] ?>" class="level-0"><?= $one_document['title'] ?></option>
                                                    <? endforeach; ?>
                                                </select>

                                                <br>                
                                                <br>

                                            </td> 

                                        </tr> 

                                    </tbody>

                                </table>

                                <div class="submit">

                                    <input type="button" value="Upload videos" id="v-upload" name="uploadvideo" class="btn">
                                    <img id="ajax-loading" class="ajax-loading" src="<?= base_url() ?>assets/img/backgnds/loading.gif" style="visibility: hidden;">
                                    <div class="updated below-h2 message">

                                        <p>Please wait while creating video link</p>

                                    </div>

                                </div>

                            </form>

                        </div>

                        <div class="v-left">

                            <div id="video-preview"></div>

                        </div>

                    </div>
                    <!--/UPLOAD VIDEO-->

                    <!--ADD GALLERY-->
                    <div id="addgallery">

                        <!-- create gallery -->
                        <h2> Add new folder </h2>

                        <form accept-charset="utf-8" action="<?= base_url() ?>documents/submit_gallery" method="POST" id="addgallery_form" name="addgallery">

                            <input type="hidden" value="new-gallery" name="post_action">            

                            <table class="form-table"> 
                                <tbody>


                                    <tr valign="top"> 

                                        <td class="upload_text">New Folder:</td> 

                                        <td>

                                            <input type="text" value="" name="galleryname" size="43">

                                            <i>( Use characters: a-z, A-Z, 0-9, _ )</i>

                                        </td>

                                    </tr>

                                    <tr valign="top"> 

                                        <td class="upload_text">Folder Type</td> 

                                        <td>           

                                            <select id="post_type" name="type">
                                                <option value="0" selected="selected">--Please select </option>

                                                <? foreach (config_item('page_types') as $page_type): ?>

                                                <option value="<?= $page_type ?>">
                                                    <? if ($page_type == 'news') $page_type = 'Latest News'; ?>
                                                    <?= ucfirst($page_type); ?>

                                                </option>

                                                <? endforeach; ?>
                                            </select>

                                        </td> 

                                    </tr>

                                    <tr valign="top"> 

                                        <td class="upload_text">Parent</td> 

                                        <td>         
                                            
                                            
                                            <?
                                            $_GET['_cur_level'] = ''; 
                                            $_GET['_start_level'] = ''; 


                                            ?>

                                            <select id="parent_id" name="parent_id">
                                                <option value="0" selected="selected">(no parent)</option>
                                                <?foreach (config_item('page_types') as $page_type):?>
                                                <optgroup label="<?= ucfirst($page_type); ?>">
                                                    <?= parents_finder(0, $page_type, TRUE); ?>
                                                    <? endforeach; ?>
                                            </select>

                                            <?
                                            unset($_GET['_cur_level']);
                                            unset($_GET['_start_level']);
                                            ?>
                                            

                                            <br>                
                                            <br>

                                        </td> 

                                    </tr> 

                                </tbody>

                            </table>

                            <div class="submit row"> 

                                <span class="span2 ml-15> save2"><input type="submit" value="Add Folder" class="btn" id="add_gallery" disabled="disabled"></span>
                                <span class="span4 loader"><img id="ajax-loading" class="ajax-loading" src="<?= base_url() ?>assets/img/backgnds/loading.gif" style="visibility: hidden;"></span>

                            </div>

                        </form>

                    </div>
                    <!--/ADD GALLERY-->

                </div>

                <div class="clear"></div>

            </div>

        </div>

        <div class="span4">

            <div class="hero-unit">
                <h3><?= ucfirst($_GET['post_type']) ?></h3>
                <p>
                    <a class="btn btn-large" href="<?= base_url('documents/view_all?post_type=' . $_GET['post_type'] . '&type=all') ?>">
                        <i class="icon-camera"></i> View All <?= ucfirst($_GET['post_type']) ?>
                    </a>
                </p>
            </div>

        </div>

    </div>

</div> <!-- /container -->

<script type="text/javascript">

    var post_type = '<?= $_GET['post_type'] ?>';

</script>  